﻿
<link href="/SiteUI/Admin/share.css" rel="stylesheet" />
<script src="/SiteUI/res_sobiz.js"></script>

<div class="row">
    <div class="Tab-Head active" id="tabPosAuthority">
        <h4><i class="icon-security"></i>权限</h4>
    </div>
</div>
<div class="row" id="lstAuthorities">
    <div class="row authorityItemTitle">
        <div class="col-lg-2">
            业务对象
        </div>
        <div class="col-lg-2">
            权限类型
        </div>
        <div class="col-lg-4">
            说明
        </div>
        <div class="col-lg-4">
            授权
        </div>
    </div>
    <div class="loading">
        <i></i>正在努力加载数据...
    </div>
</div>
<div class="row">
    <div class="Tab-Head active" id="tabPosAcnt">
        <h4><i class="icon-accountbox"></i>人员</h4>
    </div>
</div>
<div class="row" id="lstPosAccounts">
    <div class="loading">
        <i></i>正在努力加载数据...
    </div>
</div>


<script id="tplAuthorityItem" type="text/html">
    <div class="row authorityItem">
        <div class="col-lg-2 bizobject">

        </div>
        <div class="col-lg-2 bizaction">

        </div>
        <div class="col-lg-4 remark">

        </div>
        <div class="col-lg-4 authoritied">
            <span class="status"></span>
            <div class="button btnAuth">授权</div>
            <div class="button btn-risky btnUnauth">取消授权</div>
        </div>
    </div>
</script>
<script id="tplAcntItem" type="text/html">
    <div class="col-lg-4 acntItemBox">
        <div class="acntItem">
            <img class="an-headimg"/>
            <div class="an-info">
                <h4 class="an-name"></h4>
            </div>
        </div>
    </div>
</script>

<script>
    pvPositionDetail = {
        position:{
        },
        tplAI: $($("#tplAuthorityItem")[0].innerHTML),
        tplAN:$($("#tplAcntItem")[0].innerHTML),
        onGetDetailEnd: function (rtn) {
            $(".loading").hide();
            $("#lstAuthorities").children(".authorityItem").remove();
            $("#lstPosAccounts").children(".acntItemBox").remove();
            pvPositionDetail.position = rtn.Data;
            pvPositionDetail.position.authorities.forEach(function (a) {
                var ai = pvPositionDetail.tplAI.clone();
                ai.attr("authorityid", a.idstr);
                //ai.children(".app").vl(res_sobiz.var.App[a.app].Title);
                ai.children(".bizobject").vl(res_sobiz.var.App[a.app].BizObject[a.bizobject].Title);
                ai.children(".bizaction").vl(res_sobiz.var.App[a.app].BizObject[a.bizobject].BizAction[a.bizaction].Title);
                ai.children(".remark").vl(res_sobiz.var.App[a.app].BizObject[a.bizobject].BizAction[a.bizaction].Remark);
                if (a.roleid) {
                    ai.children(".authoritied").addClass("positive").children(".status").eq(0).vl("已授权");
                }
                else {
                    ai.children(".authoritied").children(".status").eq(0).vl("-");
                }
                ai.appendTo("#lstAuthorities");
            });

            pvPositionDetail.position.mainacnts.forEach(function (a) {
                var an = pvPositionDetail.tplAN.clone();
                an.children(".acntItemBox").children(".acntItem").attr("acntid", a.idstr).addClass("bymainposition");
                an.find(".an-headimg").attr("src",a.headimg);
                an.find(".an-name").vl(a.username);
                an.appendTo("#lstPosAccounts");
            });

            pvPositionDetail.position.partacnts.forEach(function (a) {
                var an = pvPositionDetail.tplAN.clone();
                an.children(".acntItemBox").children(".acntItem").attr("acntid", a.idstr).addClass("bypartposition");
                an.find(".an-headimg").attr("src",a.headimg);
                an.find(".an-name").vl(a.realname||a.username);
                an.appendTo("#lstPosAccounts");
            });

        },
        LoadPosition: function (posid) {
            $("#lstAuthorities").children(".authorityItem").remove();
            $("#lstPosAccounts").children(".acntItemBox").remove();
            $(".loading").show();
            if (posid) {
                $.getJSON("/Admin/GetPositionDetail", { "posid": posid }, pvPositionDetail.onGetDetailEnd);
            }
        },
        AddAuth: function (ev) {
            var aid = $(ev.currentTarget).parents(".authorityItem").eq(0).attr("authorityid");
            if (aid) {
                $.getJSON("/Admin/AddPositionAuth", { posid: pvPositionDetail.position.idstr, authorityid: aid });
                $(ev.currentTarget).parents(".authoritied").addClass("positive").children(".status").eq(0).vl("已授权");
            }
        },
        RemoveAuth: function (ev) {
            var aid = $(ev.currentTarget).parents(".authorityItem").eq(0).attr("authorityid");
            if (aid) {
                $.getJSON("/Admin/RemovePositionAuth", { posid: pvPositionDetail.position.idstr, authorityid: aid });
                $(ev.currentTarget).parents(".authoritied").removeClass("positive").children(".status").eq(0).vl("-");
            }
        }
    }
    $(function () {
        $("#lstAuthorities").delegate(".btnAuth", "click", pvPositionDetail.AddAuth);
        $("#lstAuthorities").delegate(".btnUnauth", "click", pvPositionDetail.RemoveAuth);
    })
</script>
